//			function change() {
//				var lis = document.getElementsByTagName("a");
//
//				for (var j = 0; j < lis.length; j++) {
//					lis[j].onmouseover = function() {
//						this.className = "active";
//					}
//						
//					lis[j].onmouseout = function() {
//						this.className = "";
//					}
//	
//				}
//			}
$(document).ready(function() {
	//显示经理基本信息
	$("#MangerProfile").click(function() {

		if ($("#myProfileisGet").val() == "false") {
			$.post("../../UserInfoManagementServlet", {
				"Type": "Manager",
				"peoId": $("#peoId").html()
			}, function(ret) {
				if (ret != null) {
					console.log(ret);
					$("#manId").val(ret.manId);
					$("#manNameRow").val(ret.manName);
					$("#manName").val(ret.manName);
					$("#manLevel").val(ret.manLevel);
					$("#manWorkPhone").val(ret.manWorkPhone);
					$("#manWorkPhoneRow").val(ret.manWorkPhone);
					$("#emailMan").val(ret.email);
					$("#emailManRow").val(ret.email);
					$("#myProfileisGet").val("true");
				}
			});
		}
	});
	//新密码检验
	$("#newPWD").change(function() {
		var first = $("#newPWDMan").val();
		var second = $("#repeatPWDMan").val();
		if (first.length < 6 || first.length > 20) {
			$("#pwdtipswrong").html("<i class='fa fa-remove'></i>您的新密码长度不符合规定（6-20），请重试！");
			return;
		}
		if (first.replace(/(^\s*)|(\s*$)/g, '') == null || first.replace(/(^\s*)|(\s*$)/g, '') == "") {
			$('#pwdtipswrong').html("<i class='fa fa-remove'></i>新密码不可为空或您没有输入有效的字符！");
			return;
		}
		if (/[^0-9]/.test(first)) {
			$('#pwdtipswrong').html("<i class='fa fa-remove'></i>新密码值不可为非数字字符！");
			return;
		}
		$("#pwdtipswrong").html("");
	});
	//重复密码检验
	$("#repeatPWDMan").change(function() {
		var first = $("#newPWDMan").val();
		var second = $("#repeatPWDMan").val();
		if (first != second) {
			$("#pwdtipswrong").html("<i class='fa fa-remove'></i>两次密码输入不一致");
			return;
		}
		if (second.length < 6 || second.length > 20) {
			$("#pwdtipswrong").html("<i class='fa fa-remove'></i>您的新密码长度不符合规定（6-20），请重试！");
			return;
		}
		if (second.replace(/(^\s*)|(\s*$)/g, '') == null || second.replace(/(^\s*)|(\s*$)/g, '') == "") {
			$('#pwdtipswrong').html("<i class='fa fa-remove'></i>新密码不可为空或您没有输入有效的字符！");
			return;
		}

		$("#pwdtipswrong").html("");
		$("#resetPWDByMan").css("display", "inline");

	});
	//重置密码
	$("#resetPWDByMan").click(function() {
		var peoId = $("#peoId").html();
		var PWD = $("#repeatPWDMan").val();
		$.post("../../UserInfoManagementServlet", {
			"Type": "ChangePWD",
			"peoId": peoId,
			"PWD": PWD
		}, function(ret) {
			alert(ret)
			if (ret != "null") {
				swal({
					title: "修改成功！",
					text: "您的新密码是：" + PWD + "\n请注意牢记！",
					type: "success",
				});
			} else {
				swal({
					title: "修改失败！",
					text: "请稍后重试！",
					type: "error",
				});
			}
		});
	});
	//退出登录
	$("#logout").click(function() {
		swal({
			title: "退出？",
			text: "尊敬的" + $("#peoId").html() + "您即将退出系统，我们不会为你保存您未保存的数据，您确定吗？",
			showConfirmButton: true,
			showCancelButton: true,
			confirmButtonText: "退出",
			cancelButtonText: "取消",
			closeOnConfirm: false,
			type: "warning",
		}, function(isConfirm) {
			if (isConfirm) {
				$.post("../../LoginServlet", {
					"Type": "logout",
				}, function(ret) {
					if (ret != null) {

						swal({
							title: "退出成功！",
							text: "您已成功退出系统，期待您的下次使用！",
							showConfirmButton: false,
							type: "success",
						});

						setTimeout("$(location).attr('href', '../mylogin.html')", 2000);
					}
				});
			}
		});
	});
	/* $('#myDepositTable tr td .onck').each(function () {
		console.log("1231231231");
		$(this).click(function(){
			console.log($(this).val()) ;
		})
		
		
	}) */
	//获取质押物记录对应的客户的客户信息
	$("#myDepositTable").on("click", ".onck", function() {
		console.log(typeof($(this).parent().parent().children().eq(2).html()))
		var peoId = $(this).parent().parent().children().eq(2).html();
		console.log("666666" + $("#lastID").val() + " " + peoId)
		// console.log($('#myDepositTable tr td .onck'));
		if ($("#lastID").val() != peoId) {
			$().printCutomerDetails(peoId);
			$("#myCustomerTable").css("display", "inline");
		}

		$("#lastID").val(peoId);
	});
	//循环输出导表格
	$.fn.printDepositManage = function(ret) {
		$("tr[name='deposits']").remove();
		for (let i = 0; i < ret.length; i++) {
			$("#myDepositTable").append(
				"<tr name = 'deposits'>" +
				"<td>" + ret[i].depositId + "</td>" +
				"<td>" + ret[i].manId + "</td>" +
				"<td>" + ret[i].cusId + "</td>" +
				"<td>" + ret[i].depName + "</td>" +
				"<td>" + ret[i].depNum + "</td>" +
				"<td>" + ret[i].depGuessPrice + "</td>" +
				"<td>" + ret[i].okDate + "</td>" +
				"<td>" + "<button  class='onck'>获取</button>" + "</td>" +
				"</tr>"
			);
		}
	}
	//刷新历史信用
	$("#refreshDep").click(function() {

		$(this).attr("disabled", true);
		$.post("../../ManageServlet", {
			"Type": "Refresh",
			"peoId": $("#peoId").html()
		}, function(ret) {
			if (ret != null) {
				console.log(ret);
				$().printDepositManage(ret);
				$(this).attr("disabled", false);
			} else {
				$(this).attr("disabled", false);
				$(this).html("刷新失败");
			}
		});
	});
	//查询我经手的质押物记录
	$("#showMyDepositManage").click(function() {
		if ($("#MyDepositManageisGet").val() == "false") {
			$("#showMyDepositManage").attr("disabled", true);
			$("#showMyDepositManage").html("请稍后正在查询...");
			$.post("../../ManageServlet", {
				"Type": "MyDepositManage",
				"peoId": $("#peoId").html()
			}, function(ret) {
				console.log(ret)
				if (ret != null) {
					console.log(ret);
					$().printDepositManage(ret);

					$("#showMyDepositManage").attr("disabled", false);
					$("#showMyDepositManage").html("显示我的正在进行的经手质押物订单");
					$("#MyDepositManageisGet").val("true");
				} else {
					$("#showMyDepositManage").attr("disabled", false);
					$("#showMyDepositManage").html("查询失败");
				}
			});
		}
	});
	$("#ManagerProfileChange").click(function() {

		console.log($("#manName").val());
		console.log($("#manNameRow").val());
		console.log($("#manWorkPhone").val());
		console.log($("#manWorkPhoneRow").val());
		if ($("#manName").val() == $("#manNameRow").val()) {
			if ($("#manWorkPhone").val() == $("#manWorkPhoneRow").val()) {
				if ($("#emailMan").val() == $("#manWorkPhoneRow").val()) {
					swal({
						title: "警告！",
						text: "您没有修改任何数据！",
						type: "warning",
					});
					return;
				}

			}
		}
		var myreg = /^[1][3,4,5,7,8][0-9]{9}$/;
		if (!myreg.test($("#manWorkPhone").val())) {
			swal({
				title: "警告！",
				text: "手机号格式不正确！",
				type: "warning",
			});
			return;
		}
		var myreg = /^([a-zA-Z]|[0-9])(\w|\-)+@[a-zA-Z0-9]+\.([a-zA-Z]{2,4})$/;
		if (!myreg.test($("#manWorkPhone").val())) {
			swal({
				title: "警告！",
				text: "手机号格式不正确！",
				type: "warning",
			});
			return;
		}
		$.post("../../UserInfoManagementServlet", {
			"Type": "ManChangeProfile",
			"peoId": $("#peoId").html(),
			"manName": $("#manName").val(),
			"manWorkPhone": $("#manWorkPhone").val(),
			"manLevel": $("#manLevel").val(),
		}, function(ret) {
			console.log(ret)
			if (ret != "null") {
				swal({
					title: "修改成功！",
					text: "您的数据已修改，两秒后为您刷新页面！",
					showConfirmButton: false,
					type: "success",
				});
				setTimeout("location.reload() ", 2000);

			} else {
				swal({
					title: "修改失败！",
					text: "请稍后重试！两秒后为您刷新页面！",
					showConfirmButton: false,
					type: "error",
				});
				setTimeout("location.reload() ", 2000);
			}
		});

	});
});

function showthis(obj) {
	var classes = document.getElementsByName("contenttoshow");
	var lis = document.getElementsByTagName("a");
	for (var i = 0; i < lis.length; i++) {
		lis[i].className = "";
	}
	for (var i = 0; i < classes.length; i++) {
		classes[i].style.display = "none";
	}
	document.getElementById(obj.id).className = "active";
	document.getElementsByClassName(obj.id)[0].style.display = "block";
}

function btncolorover(obj) {
	obj.className = "btn-active";
}

function btncolorout(obj) {
	obj.className = "";
}
